/**
 * Created by fkjslee on 2017/12/29.
 */

 var url = "http://118.24.11.68:8080";
// var url = "http://172.22.244.97:8080";

function btnLog() {
    var account = document.getElementById("log_account_input");
    var pwd = document.getElementById("log_pwd_input");
    var data = "account=" + account.value + "&pwd=" + pwd.value;
    var request = new XMLHttpRequest();
    request.open("POST", url + "/login?" + data);
    request.send();
    request.onreadystatechange = function () {
        if(request.readyState === 4) {
            if(request.status === 200) {
                var text = JSON.parse(request.responseText);
                if(text.type === "e") {
                    window.location.href= url + "/returnOrCheck/returnOrCheck.html" +
                            "?account=" + account.value;
                } else if(text.type === "m") {
                    window.location.href= url + "/startDispensing/startDispensing.html" +
                            "?account=" + account.value;
                }
            }
            else {
                if(request.responseText === "wrongPwd")
                    alert("wrong password, please check again");
                else
                    alert("wrong account, please check again");
            }
        }
    }
}